﻿using MediatR;
using Traceability.App.Applications.Command.Slaughter;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Slaughter
{
    public class GetshowSlaughterCommandHand : IRequestHandler<GetshowSlaughterCommand, ApiResult<SlaughterModel>>
    {
        private readonly IBaseRepository<SlaughterModel> _slaughter;

        public GetshowSlaughterCommandHand(IBaseRepository<SlaughterModel> slaughter)
        {
            _slaughter = slaughter;
        }

        public Task<ApiResult<SlaughterModel>> Handle(GetshowSlaughterCommand request, CancellationToken cancellationToken)
        {
           var result=new ApiResult<SlaughterModel>();
            var slaugh = _slaughter.GetAll().FirstOrDefault(x => x.Batch == request.Batch);
            if (slaugh != null)
            { 
                result.data=slaugh;
                result.Message = "信息查询";
            }

            return Task.FromResult(result); 
        }
    }
}
